home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / nethandler.lha / NetHandler / handler / dir.c < prev    next >
C/C++ Source or Header  |  1989-09-16  |  8KB  |  256 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* |_o_o|\\ Copyright (c) 1987, 1988 The Software Distillery.  All Rights  */
  3. /* |. o.| || Reserved.  This program may not be distributed without the    */
  4. /* | .  | || permission of the authors:                            BBS:    */
  5. /* | o  | ||   John Toebes     Doug Walker    Dave Baker                   */
  6. /* |  . |//                                                                */
  7. /* ======                                                                  */
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9. /* Directory Manipulation */
  10. /*  ActCreateDir ActExamine ActExNext ActParent */
  11. #include "handler.h"
  12.  
  13.  
  14. void ActCreateDir(global,pkt)
  15. GLOBAL global;
  16. struct DosPacket *pkt;              /* a pointer to the dos packet sent      */
  17. /* Arg1 - Lock */
  18. /* Arg2 - name */
  19. /* Arg3 (optional) Attributes */
  20. {
  21.    struct FileLock *flock;
  22.    NETPTR nlock;
  23.  
  24.    BUG(("ActCreateDir\n"));
  25.  
  26.    if((!(flock=(struct FileLock *)pkt->dp_Arg1) || 
  27.        !(nlock=(NETPTR)flock->fl_Key)->RDevice))
  28.    {
  29.       /* The idiot is trying to create a directory in NET: */
  30.       BUG(("ActCreateDir: Can't create dir in NET:, giving up\n"))
  31.       pkt->dp_Res1 = NULL;
  32.       pkt->dp_Res2 = ERROR_WRITE_PROTECTED;
  33.       return;
  34.    }
  35.    global->RP.Type = pkt->dp_Type;
  36.    global->RP.Arg1 = (LONG)nlock->RPtr;
  37.    MBSTR(pkt->dp_Arg2, global->RP.Data);
  38.    global->RP.Arg3 = pkt->dp_Arg3;
  39.    global->RP.DLen = BSTRLEN(global->RP.Data)+1;
  40.    if(global->RP.DLen == 1) global->RP.DLen = 0;
  41.  
  42.    if(!RemotePacket(global, nlock) && pkt->dp_Res1)
  43.    {
  44.       pkt->dp_Res1 = MKBADDR(CreateLock(global, nlock,
  45.                                (RPTR)pkt->dp_Res1, ACCESS_READ));
  46.    }
  47. }
  48.  
  49. /*-------------------------------------------------------------------------*/
  50. /* Structure of the FileInfoBlock                                          */
  51. /* struct FileInfoBlock {                                                  */
  52. /*    LONG fib_DiskKey;           Location on disk of entry                */
  53. /*    LONG fib_DirEntryType;      <0 plain file, >0 a directory            */
  54. /*    char fib_FileName[108];     Null terminated name of file             */
  55. /*    LONG fib_Protection;        Protection bits for the file             */
  56. /*    LONG fib_EntryType;         Internal for Dos use                     */
  57. /*    LONG fib_Size;              Length of file in bytes                  */
  58. /*    LONG fib_NumBlocks;         Length of file in blocks                 */
  59. /*    struct DateStamp fib_Date;  File creation date                       */
  60. /*    char fib_Comment[116];      Comment associated with file             */
  61. /*    };                                                                   */
  62. /*-------------------------------------------------------------------------*/
  63.  
  64. static void PNum U_ARGS((char *, int));
  65.  
  66. #define UPSPOT  17
  67. #define TOTSPOT 24
  68. static char status[] = "\53Network status: xxx of xxx nodes responding";
  69.  
  70. static void PNum(string, num)
  71. char *string;
  72. int num;
  73. {
  74.    static char *digits = " 123456789";
  75.    /* Format a number into 3 character positions of a string */
  76.    /* Number must be between 1 and 999 inclusive */
  77.    num %= 1000;
  78.    string[0] = digits[num/100]; num %= 100;
  79.    string[1] = digits[num/10];  num %= 10;
  80.    string[2] = (num ? digits[num] : '0');
  81. }
  82.  
  83. void ExDotInfo U_ARGS((GLOBAL, struct FileInfoBlock *));
  84.  
  85. void ExDotInfo(global, info)
  86. GLOBAL global;
  87. struct FileInfoBlock *info;
  88. {
  89.    BUGBSTR("ExDotInfo for ", info->fib_FileName);
  90.    strcpy(info->fib_FileName+(info->fib_FileName[0]+1), ".info");
  91.    info->fib_FileName[0] += 5;
  92.    info->fib_EntryType =
  93.    info->fib_DirEntryType = -3;
  94.    info->fib_Protection = 0L;
  95.    info->fib_Size = 974;
  96.    info->fib_NumBlocks = 2;
  97.    info->fib_Comment[0] = '\0';
  98.  
  99.    global->pkt->dp_Res1 = DOS_TRUE;
  100. }
  101.  
  102.  
  103. static void ExRoot U_ARGS((GLOBAL, struct FileInfoBlock *));
  104.  
  105. static void ExRoot(global, info)
  106. GLOBAL global;
  107. struct FileInfoBlock *info;
  108. {
  109.    BUG(("ExRoot\n"))
  110.    /* Examine on the root of NET: */
  111.    info->fib_DiskKey = (LONG)&global->netchain;
  112.    info->fib_DirEntryType = info->fib_EntryType = 2;
  113.    MBSTR(global->netchain.name, info->fib_FileName);
  114.    info->fib_Protection = 0;
  115.    info->fib_NumBlocks = global->numnodes;
  116.    info->fib_Size = 0;
  117.    info->fib_Date.ds_Days = 3000;  /* Pick a number */
  118.    info->fib_Date.ds_Minute =
  119.    info->fib_Date.ds_Tick = 0L;
  120.    strcpy(info->fib_Comment, status);
  121.    PNum(info->fib_Comment+UPSPOT, global->upnodes);
  122.    PNum(info->fib_Comment+TOTSPOT, global->numnodes);
  123.  
  124.    global->pkt->dp_Res1 = DOS_TRUE;
  125. }
  126.  
  127. static void ExRootNext U_ARGS((GLOBAL, struct FileInfoBlock *));
  128.  
  129. static void ExRootNext(global, info)
  130. GLOBAL global;
  131. struct FileInfoBlock *info;
  132. {
  133.    struct NetNode *node;
  134.  
  135.    /* Examine next in the root of NET: */
  136.    BUG(("ExRootNext\n"))
  137.  
  138.    node = (struct NetNode *)info->fib_DiskKey;
  139.  
  140.    /* If the node name is the same length as the filename, we haven't */
  141.    /* returned the exnext of the .info file yet;  do so               */
  142.    if(node != &global->netchain && 
  143.       info->fib_FileName[0] > 0 &&
  144.       node->name[0] == info->fib_FileName[0])
  145.    {
  146.       ExDotInfo(global, info);
  147.       return;
  148.    }
  149.  
  150. #if 0
  151.    for(node=node->next; 
  152.        node && node->status != NODE_UP;
  153.        node=node->next);
  154. #else
  155.    node = node->next;
  156. #endif
  157.  
  158.    if(!node)
  159.    {
  160.       global->pkt->dp_Res1 = DOS_FALSE;
  161.       global->pkt->dp_Res2 = ERROR_NO_MORE_ENTRIES;
  162.       BUG(("Returning ERROR_NO_MORE_ENTRIES\n"));
  163.       return;
  164.    }
  165.    
  166.    info->fib_DiskKey = (LONG)node;
  167.    info->fib_DirEntryType = info->fib_EntryType = 2;
  168.    MBSTR(node->name, info->fib_FileName);
  169.    BUGBSTR("ExNext: Filename is ", info->fib_FileName);
  170.    info->fib_Protection = 0L;
  171.    info->fib_NumBlocks = 1;
  172.    info->fib_Size = 0;
  173.    info->fib_Date.ds_Days = 3000;
  174.    info->fib_Date.ds_Minute =
  175.    info->fib_Date.ds_Tick = 0L;
  176.    info->fib_Comment[0] = '\0';
  177.  
  178.    global->pkt->dp_Res1 = DOS_TRUE;
  179. }
  180.  
  181. void ActExamine(global, pkt)
  182. GLOBAL global;
  183. struct DosPacket *pkt;              /* a pointer to the dos packet sent    */
  184. /* Arg1: Lock of object to examine */
  185. /* Arg2: FileInfoBlock to fill in */
  186. {
  187.    NETPTR nlock;
  188.    struct FileLock *flock;
  189.    struct FileInfoBlock *info;
  190.  
  191.    BUG(("ActExamine/ActExNext\n"));
  192.    
  193.    info = (struct FileInfoBlock *)pkt->dp_Arg2;
  194.  
  195.    if((!(flock=(struct FileLock *)pkt->dp_Arg1) || 
  196.        !(nlock=(NETPTR)flock->fl_Key)->RDevice))
  197.    {
  198.       if(pkt->dp_Type == ACTION_EXAMINE_OBJECT)
  199.          ExRoot(global, info);
  200.       else
  201.          ExRootNext(global, info);
  202.       return;
  203.    }
  204.  
  205.    BUG(("ActEx: Lock %lx on node %s\n",nlock->RPtr,nlock->NetNode->name+1));
  206.    global->RP.Type = pkt->dp_Type;
  207.    global->RP.Arg1 = (LONG)nlock->RPtr;
  208.  
  209.    MQ(info, global->RP.Data, sizeof(struct FileInfoBlock));
  210.    BUGBSTR("ActEx: filename ", info->fib_FileName);
  211.  
  212.    global->RP.DLen = sizeof(struct FileInfoBlock);
  213.  
  214.    if(!RemotePacket(global, nlock))
  215.    {
  216.       MQ(global->RP.Data, info, sizeof(struct FileInfoBlock));
  217.       BUGBSTR("ActEx: Returned filename ", info->fib_FileName);
  218.    }
  219. }
  220.  
  221. void ActParent(global,pkt)
  222. GLOBAL global;
  223. struct DosPacket *pkt;              /* a pointer to the dos packet sent      */
  224. /* Arg1 - Lock */
  225. {
  226.    struct FileLock *flock;
  227.    NETPTR nlock;
  228.  
  229.    BUG(("ActParent\n"));
  230.  
  231.    /* If this is the root of NET:, return NULL */
  232.    if((!(flock=(struct FileLock *)pkt->dp_Arg1) || 
  233.        !(nlock=(NETPTR)flock->fl_Key)->RDevice))
  234.    {
  235.       pkt->dp_Res1 = NULL;
  236.       return;
  237.    }
  238.  
  239.    global->RP.Type = pkt->dp_Type;
  240.    global->RP.Arg1 = (LONG)nlock->RPtr;
  241.    global->RP.DLen = 0;
  242.  
  243.    if(RemotePacket(global, nlock)) return;
  244.       
  245.    if(pkt->dp_Res1 == NULL)
  246.    {
  247.       if(pkt->dp_Res2) return;  /* Error on other side */
  248.  
  249.       /* Null lock from other side, return a lock on our root */
  250.       nlock = &global->netchain.RootLock;
  251.    }
  252.  
  253.    pkt->dp_Res1 = MKBADDR(CreateLock(global, nlock,
  254.                           (RPTR)pkt->dp_Res1, ACCESS_READ));
  255. }
  256.